<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>maint/utils/unrefglobals.pl</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#TOP'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/maint.html'>maint</a>/<a href='../files/maint--utils.html'>utils</a>/unrefglobals.pl</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/maint.html'>maint</a>/<a href='../files/maint--utils.html'>utils</a>/unrefglobals.pl</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 maint/utils/unrefglobals.pl'  /> */</em>
<hr />
<pre>
<a id='L1' name='L1'></a>#!/usr/bin/perl
<a id='L2' name='L2'></a> 
<a id='L3' name='L3'></a># Copyright (c) 2003, Pavel Roskin
<a id='L4' name='L4'></a># The Midnight Commander is free software: you can redistribute it
<a id='L5' name='L5'></a># and/or modify it under the terms of the GNU General Public License as
<a id='L6' name='L6'></a># published by the Free Software Foundation, either version 3 of the License,
<a id='L7' name='L7'></a># or (at your option) any later version.
<a id='L8' name='L8'></a>#
<a id='L9' name='L9'></a># The Midnight Commander is distributed in the hope that it will be useful,
<a id='L10' name='L10'></a># but WITHOUT ANY WARRANTY; without even the implied warranty of
<a id='L11' name='L11'></a># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<a id='L12' name='L12'></a># GNU General Public License for more details.
<a id='L13' name='L13'></a>#
<a id='L14' name='L14'></a># You should have received a copy of the GNU General Public License
<a id='L15' name='L15'></a># along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
<a id='L16' name='L16'></a> 
<a id='L17' name='L17'></a># Run this script on the map with cross-reference generated by GNU ld,
<a id='L18' name='L18'></a># and it will generate a list of symbols that don't need to be global.
<a id='L19' name='L19'></a># To create the map, run something like this:
<a id='L20' name='L20'></a># make LDFLAGS=-Wl,-Map,output.map,--cref
<a id='L21' name='L21'></a> 
<a id='L22' name='L22'></a>use strict;
<a id='L23' name='L23'></a> 
<a id='L24' name='L24'></a>my %symbols;
<a id='L25' name='L25'></a>my %syms;
<a id='L26' name='L26'></a>my %objs;
<a id='L27' name='L27'></a> 
<a id='L28' name='L28'></a>if ($#ARGV != 0) {
<a id='L29' name='L29'></a>        print "Usage: unrefglobals.pl mapfile\n";
<a id='L30' name='L30'></a>        exit 1;
<a id='L31' name='L31'></a>}
<a id='L32' name='L32'></a> 
<a id='L33' name='L33'></a>if (!open (MAP, "$ARGV[0]")) {
<a id='L34' name='L34'></a>        print "Cannot open file \"$ARGV[0]\"\n";
<a id='L35' name='L35'></a>        exit 1;
<a id='L36' name='L36'></a>}
<a id='L37' name='L37'></a> 
<a id='L38' name='L38'></a>my $line;
<a id='L39' name='L39'></a>my $next_line = &lt;MAP&gt;;
<a id='L40' name='L40'></a>while (1) {
<a id='L41' name='L41'></a>        last unless $next_line;
<a id='L42' name='L42'></a>        $line = $next_line;
<a id='L43' name='L43'></a>        $next_line = &lt;MAP&gt;;
<a id='L44' name='L44'></a>        next unless ($line =~ m{^[A-Za-z_][A-Za-z0-9_]*  +[^ /][^ ]+\.o$} or
<a id='L45' name='L45'></a>                     $line =~ m{^[A-Za-z_][A-Za-z0-9_]*  +[^ /][^ ]+\.a\([^ ]+\.o\)$});
<a id='L46' name='L46'></a>        if (!$next_line or ($next_line !~ /^ /)) {
<a id='L47' name='L47'></a>                my @arr = split (' ', $line);
<a id='L48' name='L48'></a>                $symbols{$arr[0]} = $arr[1];
<a id='L49' name='L49'></a>                $syms{$arr[0]} = 1;
<a id='L50' name='L50'></a>                $objs{$arr[1]} = 1;
<a id='L51' name='L51'></a>        }
<a id='L52' name='L52'></a>}
<a id='L53' name='L53'></a> 
<a id='L54' name='L54'></a>close(MAP);
<a id='L55' name='L55'></a> 
<a id='L56' name='L56'></a>foreach my $obj (sort keys %objs) {
<a id='L57' name='L57'></a>        print "$obj\n";
<a id='L58' name='L58'></a>        foreach my $sym (sort keys %syms) {
<a id='L59' name='L59'></a>                print "\t$sym\n" if ($symbols{$sym} eq $obj);
<a id='L60' name='L60'></a>        }
<a id='L61' name='L61'></a>}
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+61 maint/utils/unrefglobals.pl'  /> */</em>
</body>
</html>
